home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / fabwindow.py < prev    next >
Text File  |  2009-10-09  |  24KB  |  608 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2003-2009 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22. # StdLib
  23.  
  24. # Local
  25. from base.g import *
  26. from ui_utils import *
  27.  
  28. # Qt
  29. from PyQt4.QtCore import *
  30. from PyQt4.QtGui import *
  31.  
  32. # Main window
  33. from fabwindow_base import Ui_MainWindow
  34.  
  35. fax_avail = True
  36. try:
  37.     from fax import fax
  38. except ImportError:
  39.     # This can fail on Python < 2.3 due to the datetime module
  40.     log.error("Fax address book disabled - Python 2.3+ required.")
  41.     fax_avail = False
  42.  
  43.  
  44.  
  45. class FABWindow(QMainWindow,  Ui_MainWindow):
  46.     def __init__(self, parent):
  47.         QMainWindow.__init__(self, parent)
  48.         self.setupUi(self)
  49.         self.group = u'All' # current group
  50.         self.name = None # current name
  51.         self.updating_group = False
  52.         self.updating_name = False
  53.  
  54.         self.user_settings = UserSettings()
  55.         self.user_settings.load()
  56.         self.user_settings.debug()
  57.  
  58.         self.initDB()
  59.         self.initUi()
  60.  
  61.         QTimer.singleShot(0, self.updateUi)
  62.  
  63.  
  64.     def initDB(self):
  65.         self.db =  fax.FaxAddressBook()
  66.  
  67.         # Fixup data from old-style database
  68.         data = self.db.get_all_records()
  69.         for d in data:
  70.             if u'All' not in data[d]['groups']:
  71.                 data[d]['groups'].append(u'All')
  72.  
  73.         if not data:
  74.             self.db.set('__' + utils.gen_random_uuid(), '', '', '', '', [u'All'], '')
  75.  
  76.  
  77.     def initUi(self):
  78.         # Application icon
  79.         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
  80.  
  81.         self.NewGroupAction.setIcon(QIcon(load_pixmap('new_group', '24x24')))
  82.         self.NewGroupFromSelectionAction.setIcon(QIcon(load_pixmap('new_group_from_selection', '24x24')))
  83.         self.RenameGroupAction.setIcon(QIcon(load_pixmap('rename_group', '24x24')))
  84.         self.RemoveGroupAction.setIcon(QIcon(load_pixmap('remove_group', '24x24')))
  85.         self.NewNameAction.setIcon(QIcon(load_pixmap('new_user', '24x24')))
  86.         self.RemoveNameAction.setIcon(QIcon(load_pixmap('remove_user', '24x24')))
  87.         self.AddToGroupAction.setIcon(QIcon(load_pixmap('add_to_group', '24x24')))
  88.         self.RemoveFromGroupAction.setIcon(QIcon(load_pixmap('remove_from_group', '24x24')))
  89.  
  90.         self.connect(self.QuitAction, SIGNAL("triggered()"), self.close)
  91.         self.connect(self.NewGroupAction, SIGNAL("triggered()"), self.NewGroupAction_triggered)
  92.         self.connect(self.NewGroupFromSelectionAction, SIGNAL("triggered()"), self.NewGroupFromSelectionAction_triggered)
  93.         self.connect(self.RenameGroupAction, SIGNAL("triggered()"), self.RenameGroupAction_triggered)
  94.         self.connect(self.RemoveGroupAction, SIGNAL("triggered()"), self.RemoveGroupAction_triggered)
  95.         self.connect(self.NewNameAction, SIGNAL("triggered()"), self.NewNameAction_triggered)
  96.         self.connect(self.RemoveNameAction, SIGNAL("triggered()"), self.RemoveNameAction_triggered)
  97.         self.connect(self.ImportAction, SIGNAL("triggered()"), self.ImportAction_triggered)
  98.         self.connect(self.RemoveFromGroupAction, SIGNAL("triggered()"), self.RemoveFromGroupAction_triggered)
  99.         self.connect(self.AddToGroupAction, SIGNAL("triggered()"), self.AddToGroupAction_triggered)
  100.  
  101.         self.GroupTableWidget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
  102.         self.NameTableWidget.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
  103.  
  104.         self.connect(self.Splitter, SIGNAL("splitterMoved(int, int)"), self.Splitter_splitterMoved)
  105.         self.Splitter.setChildrenCollapsible(False)
  106.         self.Splitter.setHandleWidth(self.Splitter.handleWidth()+2)
  107.  
  108.         self.GroupTableWidget.verticalHeader().hide()
  109.         self.GroupTableWidget.setShowGrid(False)
  110.         self.GroupTableWidget.setSelectionMode(QAbstractItemView.SingleSelection)
  111.         self.NameTableWidget.verticalHeader().hide()
  112.         self.NameTableWidget.setShowGrid(False)
  113.  
  114.         self.NameTableWidget.setDragEnabled(True)
  115.         self.GroupTableWidget.setAcceptDrops(True)
  116.         self.GroupTableWidget.setDropIndicatorShown(True)
  117.  
  118.         self.connect(self.GroupTableWidget, SIGNAL("itemSelectionChanged()"),
  119.                      self.GroupTableWidget_itemSelectionChanged)
  120.         self.connect(self.NameTableWidget, SIGNAL("itemSelectionChanged()"),
  121.                      self.NameTableWidget_itemSelectionChanged)
  122.         self.connect(self.NameLineEdit, SIGNAL("editingFinished()"),
  123.                      self.NameLineEdit_editingFinished)
  124.         self.connect(self.FaxNumberLineEdit, SIGNAL("editingFinished()"),
  125.                      self.FaxNumberLineEdit_editingFinished)
  126.         self.connect(self.NotesTextEdit, SIGNAL("textChanged()"),
  127.                      self.NotesTextEdit_textChanged)
  128.         self.connect(self.NotesTextEdit, SIGNAL("editingFinished()"),
  129.                      self.NotesTextEdit_editingFinished)
  130.         self.connect(self.GroupTableWidget, SIGNAL("namesAddedToGroup"),
  131.                      self.GroupTableWidget_namesAddedToGroup)
  132.  
  133.         self.FaxNumberLineEdit.setValidator(PhoneNumValidator(self.FaxNumberLineEdit))
  134.         self.NameLineEdit.setValidator(AddressBookNameValidator(self.db, self.NameLineEdit))
  135.  
  136.         self.GroupTableWidget.setContextMenuPolicy(Qt.ActionsContextMenu)
  137.         self.GroupTableWidget.addAction(self.NewGroupAction)
  138.         self.GroupTableWidget.addAction(self.NewGroupFromSelectionAction)
  139.         self.GroupTableWidget.addAction(self.RenameGroupAction)
  140.         self.GroupTableWidget.addAction(self.RemoveGroupAction)
  141.  
  142.         self.NameTableWidget.setContextMenuPolicy(Qt.ActionsContextMenu)
  143.         self.NameTableWidget.addAction(self.NewNameAction)
  144.         self.NameTableWidget.addAction(self.AddToGroupAction)
  145.         self.NameTableWidget.addAction(self.RemoveFromGroupAction)
  146.         self.NameTableWidget.addAction(self.RemoveNameAction)
  147.         self.NameTableWidget.addAction(self.NewGroupFromSelectionAction)
  148.  
  149.         self.GroupTableWidget.setDatabase(self.db)
  150.  
  151.  
  152.     def updateUi(self):
  153.         if not fax_avail:
  154.             FailureUI(self, self.__tr("<b>Fax support disabled.</b><p>Fax support requires Python 2.3."))
  155.             self.close()
  156.             return
  157.  
  158.         self.updateGroupList()
  159.         self.updateNameList()
  160.         self.updateDetailsFrame()
  161.  
  162.  
  163.     def closeEvent(self, e):
  164.         #self.NameLineEdit.emit(SIGNAL("editingFinished()"))
  165.         self.FaxNumberLineEdit.emit(SIGNAL("editingFinished()"))
  166.         self.NotesTextEdit.emit(SIGNAL("editingFinished()"))
  167.         e.accept()
  168.  
  169.  
  170.     def Splitter_splitterMoved(self, pos, index):
  171.         self.GroupTableWidget.setColumnWidth(0, self.GroupTableWidget.width())
  172.         self.NameTableWidget.setColumnWidth(0, self.NameTableWidget.width())
  173.  
  174.  
  175.     def updateGroupList(self):
  176.         self.updating_group = True
  177.         all, k = None, None
  178.         try:
  179.             headerItem = QTableWidgetItem()
  180.             headerItem.setText(self.__tr("Group"))
  181.             self.GroupTableWidget.clear()
  182.             self.GroupTableWidget.setColumnCount(1)
  183.             self.GroupTableWidget.setHorizontalHeaderItem(0, headerItem)
  184.             self.GroupTableWidget.setColumnWidth(0, self.GroupTableWidget.width())
  185.  
  186.             groups = self.db.get_all_groups()
  187.             groups.sort()
  188.             self.GroupTableWidget.setRowCount(len(groups))
  189.  
  190.             # Force All group to top of table
  191.             all = QTableWidgetItem(self.__tr("All"))
  192.             all.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
  193.             self.GroupTableWidget.setItem(0, 0, all)
  194.  
  195.             j = 1
  196.             for g in groups:
  197.                 if g == u'All':
  198.                     continue
  199.  
  200.                 i = QTableWidgetItem(QString(g))
  201.  
  202.                 if g == self.group:
  203.                     k = i
  204.  
  205.                 i.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsDropEnabled)
  206.                 self.GroupTableWidget.setItem(j, 0, i)
  207.                 j += 1
  208.  
  209.  
  210.         finally:
  211.             self.updating_group = False
  212.  
  213.             if k is not None:
  214.                 k.setSelected(True)
  215.  
  216.             elif all is not None:
  217.                 all.setSelected(True)
  218.  
  219.  
  220.     def GroupTableWidget_itemSelectionChanged(self):
  221.         if not self.updating_group:
  222.             selected_items = self.GroupTableWidget.selectedItems()
  223.             if selected_items:
  224.                 self.group = unicode(selected_items[0].text())
  225.                 self.RemoveGroupAction.setEnabled(self.group != u'All')
  226.                 self.RenameGroupAction.setEnabled(self.group != u'All')
  227.             else: # shouldn't happen?!
  228.                 self.RemoveGroupAction.setEnabled(False)
  229.                 self.RenameGroupAction.setEnabled(False)
  230.                 self.group = None
  231.  
  232.             self.updateNameList()
  233.  
  234.  
  235.     def NameTableWidget_itemSelectionChanged(self):
  236.         if not self.updating_name:
  237.             selected_items = self.NameTableWidget.selectedItems()
  238.             num_selected_items = len(selected_items)
  239.  
  240.             if num_selected_items == 0:
  241.                 self.name = None
  242.                 self.RemoveNameAction.setEnabled(False)
  243.                 self.NewGroupFromSelectionAction.setEnabled(False)
  244.                 self.RemoveFromGroupAction.setEnabled(False)
  245.                 self.AddToGroupAction.setEnabled(False)
  246.  
  247.             elif num_selected_items == 1:
  248.                 self.name = unicode(selected_items[0].text())
  249.                 self.RemoveNameAction.setEnabled(True)
  250.                 self.NewGroupFromSelectionAction.setEnabled(True)
  251.  
  252.                 self.RemoveFromGroupAction.setEnabled(self.group != u'All')
  253.                 self.AddToGroupAction.setEnabled(True) #self.group != u'All')
  254.  
  255.             else: # > 1
  256.                 self.RemoveNameAction.setEnabled(True)
  257.                 self.NewGroupFromSelectionAction.setEnabled(True)
  258.                 self.RemoveFromGroupAction.setEnabled(self.group != u'All')
  259.                 self.AddToGroupAction.setEnabled(True) #self.group != u'All')
  260.                 self.name = None
  261.  
  262.             self.updateDetailsFrame()
  263.  
  264.  
  265.     def updateNameList(self):
  266.         self.updating_name = True
  267.         m, k = None, None
  268.         try:
  269.             headerItem = QTableWidgetItem()
  270.             headerItem.setText(self.__tr("Name"))
  271.             self.NameTableWidget.clear()
  272.             self.NameTableWidget.setColumnCount(1)
  273.             self.NameTableWidget.setHorizontalHeaderItem(0,headerItem)
  274.             self.NameTableWidget.setColumnWidth(0, self.NameTableWidget.width())
  275.  
  276.             names = self.db.group_members(self.group)
  277.             filtered_names = [n for n in names if not n.startswith('__')]
  278.             filtered_names.sort()
  279.             self.NameTableWidget.setRowCount(len(filtered_names))
  280.  
  281.             for j, n in enumerate(filtered_names):
  282.                 i = QTableWidgetItem(QString(n))
  283.                 i.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsDragEnabled)
  284.                 self.NameTableWidget.setItem(j, 0, i)
  285.  
  286.                 if n == self.name:
  287.                     m = i
  288.  
  289.                 if j == 0:
  290.                     k = i
  291.  
  292.         finally:
  293.             self.updating_name = False
  294.  
  295.             if m is not None:
  296.                 m.setSelected(True)
  297.  
  298.             elif k is not None:
  299.                 k.setSelected(True)
  300.  
  301.             else: # no names, disable name frame and name actions
  302.                 self.name = None
  303.                 self.RemoveNameAction.setEnabled(False)
  304.                 self.NewGroupFromSelectionAction.setEnabled(False)
  305.                 self.RemoveFromGroupAction.setEnabled(False)
  306.                 self.AddToGroupAction.setEnabled(False)
  307.                 self.updateDetailsFrame()
  308.  
  309.  
  310.     def selectByName(self, name):
  311.         rows = self.NameTableWidget.rowCount()
  312.         for r in range(rows):
  313.             i = self.NameTableWidget.item(r, 0)
  314.             i.setSelected(name == unicode(i.text()))
  315.  
  316.  
  317.     def updateDetailsFrame(self):
  318.         if self.name is None:
  319.             self.NameFrame.setEnabled(False)
  320.             self.NameLineEdit.setText(QString())
  321.             self.FaxNumberLineEdit.setText(QString())
  322.             self.NotesTextEdit.setText(QString())
  323.  
  324.         else:
  325.             self.NameFrame.setEnabled(True)
  326.             data = self.db.get(self.name)
  327.             self.NameLineEdit.setText(self.name)
  328.             self.FaxNumberLineEdit.setText(data['fax'])
  329.             self.NotesTextEdit.setText(data['notes'])
  330.  
  331.  
  332.     def NameLineEdit_editingFinished(self):
  333.         if self.name is not None:
  334.             new_name = unicode(self.NameLineEdit.text())
  335.             if new_name != self.name:
  336.                 if QMessageBox.question(self, self.__tr("Rename?"), self.__tr("Rename '%1' to '%2'?").arg(self.name).arg(new_name), \
  337.                                         QMessageBox.Yes | QMessageBox.No) == QMessageBox.Yes:
  338.  
  339.                     self.db.rename(self.name, new_name)
  340.                     log.debug("Rename %s to %s" % (self.name, new_name))
  341.                     self.emit(SIGNAL("databaseChanged"), FAB_NAME_RENAME, self.name, new_name)
  342.                     self.updateNameList()
  343.                 else:
  344.                     self.NameLineEdit.setText(self.name)
  345.  
  346.  
  347.     def FaxNumberLineEdit_editingFinished(self):
  348.         if self.name is not None:
  349.             self.db.set_key_value(self.name, 'fax', unicode(self.FaxNumberLineEdit.text()))
  350.             self.emit(SIGNAL("databaseChanged"), FAB_NAME_DETAILS_CHANGED, self.name)
  351.  
  352.  
  353.     def NotesTextEdit_textChanged(self):
  354.         if self.name is not None:
  355.             self.db.set_key_value(self.name, 'notes', unicode(self.NotesTextEdit.document().toPlainText()))
  356.  
  357.  
  358.     def NotesTextEdit_editingFinished(self):
  359.         if self.name is not None:
  360.             self.emit(SIGNAL("databaseChanged"), FAB_NAME_DETAILS_CHANGED, self.name)
  361.  
  362.  
  363.     def NewGroupAction_triggered(self):
  364.         ok = False
  365.         g, ok = QInputDialog.getText(self, self.__tr("Enter New Group Name"), self.__tr("Name for New Group:"))
  366.         g = unicode(g)
  367.  
  368.         if g == u'All':
  369.             FailureUI(self, self.__tr("<b>Sorry, the group name cannot be 'All'.</b><p>Please choose a different name."))
  370.             ok = False
  371.  
  372.         if ok:
  373.             self.db.set('__' + utils.gen_random_uuid(), '', '', '', '', [u'All', g], '')
  374.             self.group = g
  375.             log.debug("New empty group %s" % self.group)
  376.             self.emit(SIGNAL("databaseChanged"), FAB_GROUP_ADD, self.group)
  377.             self.updateGroupList()
  378.  
  379.  
  380.     def NewGroupFromSelectionAction_triggered(self):
  381.         selected_names = [unicode(n.text()) for n in self.NameTableWidget.selectedItems()]
  382.         if selected_names:
  383.             ok = False
  384.             g, ok = QInputDialog.getText(self, self.__tr("Enter New Group Name"), self.__tr("Name for New Group:"))
  385.             g = unicode(g)
  386.  
  387.             groups = self.db.get_all_groups()
  388.  
  389.             if g in groups:
  390.                 FailureUI(self, self.__tr("<b>Sorry, the group name cannot be the same as an existing group (or 'All').</b><p>Please choose a different name."))
  391.                 ok = False
  392.  
  393.             if ok:
  394.                 self.db.update_groups(g, selected_names)
  395.                 self.group = g
  396.                 log.debug("New group %s with names %s" % (self.group, ','.join(selected_names)))
  397.                 self.emit(SIGNAL("databaseChanged"), FAB_GROUP_ADD, self.group)
  398.                 self.updateGroupList()
  399.  
  400.  
  401.     def RenameGroupAction_triggered(self):
  402.         selected_items = self.GroupTableWidget.selectedItems()
  403.         if selected_items:
  404.             old_group = unicode(selected_items[0].text())
  405.             ok = False
  406.             new_group, ok = QInputDialog.getText(self, self.__tr("Rename Group"), self.__tr("New Name for Group '%1':").arg(old_group))
  407.             new_group = unicode(new_group)
  408.             groups = self.db.get_all_groups()
  409.  
  410.             if new_group in groups:
  411.                 FailureUI(self, self.__tr("<b>Sorry, the group name cannot be the same as an existing group (or 'All').</b><p>Please choose a different name."))
  412.                 ok = False
  413.  
  414.             if ok:
  415.                 self.db.rename_group(old_group, new_group)
  416.                 log.debug("Rename group %s to %s" % (old_group, new_group))
  417.                 self.emit(SIGNAL("databaseChanged"), FAB_GROUP_RENAME, old_group, new_group)
  418.                 self.group = new_group
  419.                 self.updateGroupList()
  420.  
  421.  
  422.     def RemoveGroupAction_triggered(self):
  423.         self.db.delete_group(self.group)
  424.         log.debug("Remove group %s" % self.group)
  425.         self.emit(SIGNAL("databaseChanged"), FAB_GROUP_REMOVE, self.group)
  426.         self.group = None
  427.         self.updateGroupList()
  428.  
  429.  
  430.     def NewNameAction_triggered(self):
  431.         ok = False
  432.         t, ok = QInputDialog.getText(self, self.__tr("Enter New Name"), self.__tr("New Name:"))
  433.         if ok:
  434.             t = unicode(t)
  435.             self.addName(t)
  436.  
  437.  
  438.     def addName(self, name, fax=''):
  439.         if self.group == u'All':
  440.             g = [u'All']
  441.         else:
  442.             g = [u'All', self.group]
  443.  
  444.         self.db.set(name, '', '', '', fax, g, '')
  445.         self.name = name
  446.         log.debug("New name %s" % self.name)
  447.         self.emit(SIGNAL("databaseChanged"), FAB_NAME_ADD, self.name)
  448.         self.updateNameList()
  449.  
  450.  
  451.     def RemoveNameAction_triggered(self):
  452.         selected_names = [unicode(n.text()) for n in self.NameTableWidget.selectedItems()]
  453.         if selected_names:
  454.             for n in selected_names:
  455.                 self.db.delete(n)
  456.                 log.debug("Removing name %s" % n)
  457.                 self.emit(SIGNAL("databaseChanged"), FAB_NAME_REMOVE, n)
  458.  
  459.             self.name = None
  460.             self.updateNameList()
  461.  
  462.  
  463.     def RemoveFromGroupAction_triggered(self):
  464.         selected_names = [unicode(n.text()) for n in self.NameTableWidget.selectedItems()]
  465.         if selected_names:
  466.             log.debug("%s leaving group %s" % (','.join(selected_names), self.group))
  467.             self.db.remove_from_group(self.group, selected_names)
  468.             self.emit(SIGNAL("databaseChanged"), FAB_GROUP_MEMBERSHIP_CHANGED, self.group)
  469.             self.name = None
  470.             self.updateGroupList()
  471.  
  472.  
  473.     def GroupTableWidget_namesAddedToGroup(self, row, items): # drag n' drop handler
  474.         self.group = unicode(self.GroupTableWidget.item(row, 0).text())
  475.         self.db.add_to_group(self.group, items)
  476.         log.debug("Adding %s to group %s" % (','.join(items), self.group))
  477.         self.emit(SIGNAL("databaseChanged"), FAB_GROUP_MEMBERSHIP_CHANGED, self.group)
  478.         self.updateGroupList()
  479.  
  480.  
  481.     def AddToGroupAction_triggered(self):
  482.         selected_names = [unicode(n.text()) for n in self.NameTableWidget.selectedItems()]
  483.         if selected_names:
  484.             ok = False
  485.             all_groups = self.db.get_all_groups()
  486.  
  487.             if all_groups:
  488.                 all_groups = [g for g in all_groups if g != u'All']
  489.                 all_groups.sort()
  490.  
  491.                 dlg = JoinDialog(self, all_groups)
  492.  
  493.                 if dlg.exec_() == QDialog.Accepted:
  494.                     group = dlg.group
  495.                     if group:
  496.                         self.db.add_to_group(group, selected_names)
  497.                         self.group = group
  498.                         log.debug("Adding %s to group %s" % (','.join(selected_names), self.group))
  499.                         self.emit(SIGNAL("databaseChanged"), FAB_GROUP_MEMBERSHIP_CHANGED, self.group)
  500.                         self.updateGroupList()
  501.  
  502.             else:
  503.                 FailureUI(self, self.__tr("<b>There are no groups to join.</b><p>Use <i>New Group from Selection</i> to create a new group using these name(s)."))
  504.  
  505.  
  506.     def ImportAction_triggered(self):
  507.         result = unicode(QFileDialog.getOpenFileName(self,
  508.                          self.__tr("Import fax addresses from LDIF or vCard"),
  509.                          #user_conf.workingDirectory(),
  510.                          self.user_settings.working_dir,
  511.                          "vCard (*.vcf);;LDIF (*.ldif *.ldi)"))
  512.  
  513.         if result:
  514.             working_directory = unicode(os.path.dirname(result))
  515.             log.debug("result: %s" % result)
  516.             #user_conf.setWorkingDirectory(working_directory)
  517.             self.user_settings.working_dir = working_directory
  518.             self.user_settings.save()
  519.  
  520.             if result:
  521.                 if result.endswith('.vcf'):
  522.                     ok, error_str = self.db.import_vcard(result)
  523.                 else:
  524.                     ok, error_str = self.db.import_ldif(result)
  525.  
  526.                 if not ok:
  527.                     FailureUI(self, error_str)
  528.  
  529.                 else:
  530.                     self.updateUi()
  531.  
  532.  
  533.     def __tr(self,s,c = None):
  534.         return qApp.translate("FABWindow",s,c)
  535.  
  536.  
  537.  
  538.  
  539. class JoinDialog(QDialog):
  540.     def __init__(self, parent, groups):
  541.         QDialog.__init__(self, parent)
  542.         self.group = ''
  543.         self.setupUi(groups)
  544.  
  545.  
  546.     def setupUi(self, groups):
  547.         self.setObjectName("Dialog")
  548.         self.resize(QSize(QRect(0,0,271,107).size()).expandedTo(self.minimumSizeHint()))
  549.  
  550.         self.gridlayout = QGridLayout(self)
  551.         self.gridlayout.setObjectName("gridlayout")
  552.  
  553.         self.hboxlayout = QHBoxLayout()
  554.         self.hboxlayout.setObjectName("hboxlayout")
  555.  
  556.         self.label = QLabel(self)
  557.         self.label.setObjectName("label")
  558.         self.hboxlayout.addWidget(self.label)
  559.  
  560.         self.GroupJoinComboBox = QComboBox(self)
  561.  
  562.         sizePolicy = QSizePolicy(QSizePolicy.Expanding,QSizePolicy.Fixed)
  563.         sizePolicy.setHorizontalStretch(0)
  564.         sizePolicy.setVerticalStretch(0)
  565.         sizePolicy.setHeightForWidth(self.GroupJoinComboBox.sizePolicy().hasHeightForWidth())
  566.         self.GroupJoinComboBox.setSizePolicy(sizePolicy)
  567.         self.GroupJoinComboBox.setObjectName("comboBox")
  568.         self.hboxlayout.addWidget(self.GroupJoinComboBox)
  569.         self.gridlayout.addLayout(self.hboxlayout,0,0,1,3)
  570.  
  571.         spacerItem = QSpacerItem(20,40,QSizePolicy.Minimum,QSizePolicy.Expanding)
  572.         self.gridlayout.addItem(spacerItem,1,0,1,1)
  573.  
  574.         spacerItem1 = QSpacerItem(231,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  575.         self.gridlayout.addItem(spacerItem1,2,0,1,1)
  576.  
  577.         self.JoinButton = QPushButton(self)
  578.         self.JoinButton.setObjectName("pushButton_2")
  579.         self.gridlayout.addWidget(self.JoinButton,2,1,1,1)
  580.  
  581.         self.CancelButton = QPushButton(self)
  582.         self.CancelButton.setObjectName("pushButton")
  583.         self.gridlayout.addWidget(self.CancelButton,2,2,1,1)
  584.  
  585.         self.connect(self.GroupJoinComboBox, SIGNAL("currentIndexChanged(int)"),
  586.             self.GroupJoinComboBox_currentIndexChanged)
  587.  
  588.         for i, g in enumerate(groups):
  589.             if i == 0:
  590.                 self.group = g
  591.             self.GroupJoinComboBox.insertItem(i, g)
  592.  
  593.         self.connect(self.JoinButton, SIGNAL("clicked()"), self.accept)
  594.         self.connect(self.CancelButton, SIGNAL("clicked()"), self.reject)
  595.  
  596.         self.retranslateUi()
  597.  
  598.  
  599.     def GroupJoinComboBox_currentIndexChanged(self, i):
  600.         self.group = unicode(self.GroupJoinComboBox.currentText())
  601.  
  602.  
  603.     def retranslateUi(self):
  604.         self.setWindowTitle(QApplication.translate("Dialog", "Join Group", None, QApplication.UnicodeUTF8))
  605.         self.label.setText(QApplication.translate("Dialog", "Group to Join:", None, QApplication.UnicodeUTF8))
  606.         self.JoinButton.setText(QApplication.translate("Dialog", "Join", None, QApplication.UnicodeUTF8))
  607.         self.CancelButton.setText(QApplication.translate("Dialog", "Cancel", None, QApplication.UnicodeUTF8))
  608.